import requests
import json

if __name__ == '__main__':
    # 请求头
    headers = {
        'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
    }
    url = 'https://movie.douban.com/j/new_search_subjects'
    params = {
        'sort': 'U',
        'range': '0,10',
        'start': 0,
        'genres': '%E5%96%9C%E5%89%A7'
    }
    response = requests.get(url=url, data=params, headers=headers)
    # 获取返回的json,确认响应类型是json才能用json
    data_dict = response.json()
    with open('douban.json', 'w', encoding='utf-8') as f:
        json.dump(data_dict, fp=f, ensure_ascii=False)
    print('over!!!')
